package cn.bonoon.controllers.fmm;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.bonoon.core.plugins.GroupService;
import cn.bonoon.entities.GroupEntity;
import cn.bonoon.kernel.web.ButtonEventType;
import cn.bonoon.kernel.web.annotations.grid.GridStandardDefinition;
import cn.bonoon.kernel.web.controllers.AbstractGridController;

@Controller
@RequestMapping("s/sys/group")
public class GroupController extends AbstractGridController<GroupEntity, GroupItem>{

	private final GroupService groupService;
	
	@Autowired
	public GroupController(GroupService groupService) {
		super(groupService);
		this.groupService = groupService;
	}

	@Override
	@GridStandardDefinition(
			insertClass = GroupEditor.class, 
			updateClass = GroupEditor.class, 
			detailClass = GroupDetail.class
			)
	protected GroupService initLayoutGrid(LayoutGridRegister register) throws Exception {

		register.button("分配用户", "accounts.do", ButtonEventType.DIALOG).ordinal(20);
		register.button("分配角色", "roles.do", ButtonEventType.DIALOG).ordinal(21);
		
		register.button("访问策略", "access.do", ButtonEventType.DIALOG).ordinal(24);
		
		return groupService;
	}

	@Override
	protected Class<GroupItem> itemClass() {
		return GroupItem.class;
	}
}
